package com.googlecode.attention.rs232;
///*-
// * TestRS232Communicator.java
// *
// * Copyright (c) 2007, Stein Gunnar Bakkeby
// * All rights reserved.
// * Redistribution and use in source and binary forms, with or without
// * modification, are permitted provided that the following conditions are met:
// *
// *     * Redistributions of source code must retain the above copyright
// *       notice, this list of conditions and the following disclaimer.
// *     * Redistributions in binary form must reproduce the above copyright
// *       notice, this list of conditions and the following disclaimer in the
// *       documentation and/or other materials provided with the distribution.
// *     * Neither the name of Stein Gunnar Bakkeby nor the names of its
// *       contributors may be used to endorse or promote products derived
// *       from this software without specific prior written permission.
// *
// * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
// * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
// * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// */
//package com.googlecode.attention.rs232;
//
//import java.util.ArrayList;
//
//import com.googlecode.attention.at.AtCommand;
//import com.googlecode.attention.at.AtListener;
//import com.googlecode.attention.at.Gateway;
//import com.googlecode.attention.at.ListPDU;
//import com.googlecode.attention.PDUEntry;
//import com.googlecode.attention.SMSEntry;
//import com.googlecode.attention.Status;
//import com.googlecode.attention.sms.pdu.SMSDeliver;
//import com.googlecode.attention.sms.pdu.SMSSubmit;
//import com.googlecode.attention.util.Convert;
//import com.googlecode.attention.util.Settings;
//import com.googlecode.attention.util.ThreadTerminator;
//
///**
// * Test class for RS232Communicator.
// *
// * @author Stein Gunnar Bakkeby
// */
//public class TestRS232Communicator implements AtListener<ListPDU> {
//
//  /**
//   * Main for test class.
//   * 
//   * @param args Ignored.
//   * @throws Exception Ignored.
//   */
//  public static void main(String[] args) throws Exception {
//    RS232Communicator comm = new RS232Communicator(new Settings("src/com/googlecode/attention/rs232/rs232.properties"));
//    ThreadTerminator<TestRS232Communicator> tt = new ThreadTerminator<TestRS232Communicator>();
//    Gateway gw = new Gateway(256, comm, tt);
//    Thread t = new Thread(gw);
//    t.start();
//    
//    AtListener<ListPDU> c = new TestRS232Communicator();
//    ListPDU l = new ListPDU();
//    l.prepareExecute(Status.ALL_MESSAGES);
//    l.setListener(c);
//    gw.addAT(l);
//    
//    try {
//      Thread.sleep(25000);
//    } catch (Exception e) {
//      e.printStackTrace();
//    }
//    
//    
//    // finished, so terminate
//    System.out.println("tt.terminate()");
//    tt.terminate();
//    try {
//      Thread.sleep(4000);
//    } catch (Exception e) {
//      e.printStackTrace();
//    }
//    System.exit(0);
//  }
//
//  public void atSuccess(ListPDU command) {
//    System.out.println("SUCCESS: " + command.getCommand());
//    if (command instanceof ListPDU) {
//      final ListPDU l = (ListPDU)command;
//      final ArrayList<SMSEntry> pdus = l.getPDUs();
//      for (SMSEntry pdu : pdus) {
//        String pduStr = pdu.getPDU();
//        final int smscInfoLength = Convert.hexToInt(pduStr.substring(0, 2));
//        pduStr = pduStr.substring(2);
//        pduStr.substring(0, smscInfoLength * 2); // final String smscInfo = 
//        pduStr = pduStr.substring(smscInfoLength * 2);
//        final Status status = pdu.getStatus();
//        final String number;
//        final String message;
//        switch (status) {
//        case RECEIVED_READ_MESSAGES:
//        case RECEIVED_UNREAD_MESSAGES:
//          final SMSDeliver d = new SMSDeliver(pduStr);
//          d.decode();
//          number = d.getOriginatingAddress().getNumber();
//          //scts = d.getServiceCentreTimeStamp();
//          message = new String(Convert.intToChar(d.getUserData().toArray()));
//          break;
//          
//        case STORED_SENT_MESSAGES:
//        case STORED_UNSENT_MESSAGES:
//          final SMSSubmit s = new SMSSubmit(pduStr);
//          s.decode();
//          number = "";
//          message = new String(Convert.intToChar(s.getUserData().toArray()));
//          break;
//          
//        default:
//        case UNKNOWN:
//        case ALL_MESSAGES:
//          System.out.println("Err, unknown message found: " + status);
//          number = "Unknown";
//          message = "Unknown";
//          break;
//        }
//        System.out.println(number + " - " + message);
//      }
//    }
//  }
//
//  public void atFailure(ListPDU command) {
//    System.out.println("FAILURE: " + command.getCommand());
//  }
//}